package com.zpb.portal.controller;

import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.dto.RegisterDto;
import com.zpb.framework.domain.dto.UserDto;
import com.zpb.framework.domain.enums.ResultCodeEnum;
import com.zpb.framework.domain.vo.UserVo;
import com.zpb.framework.exception.SystemException;
import com.zpb.framework.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/13
 */
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/userInfo")
    public ApiResult<UserVo> getUserInfo() {
        return userService.queryCurrentUserInfo();
    }
    @PutMapping("/userInfo")
    public ApiResult updateUserInfo(@RequestBody UserDto userDto) {
        return userService.updateUserInfo(userDto);
    }
    @PostMapping("/register")
    public ApiResult registerUser(@RequestBody RegisterDto registerDto) {
        if (!StringUtils.hasText(registerDto.getUsername())){
            return ApiResult.failure(ResultCodeEnum.NO_USERNAME);
        }
        if (!StringUtils.hasText(registerDto.getPassword())){
            return ApiResult.failure(ResultCodeEnum.NO_PASSWORD);
        }
        if (!StringUtils.hasText(registerDto.getEmail())){
            return ApiResult.failure(ResultCodeEnum.NO_EMAIL);
        }
        if (!StringUtils.hasText(registerDto.getNickName())){
            return ApiResult.failure(ResultCodeEnum.NO_NICKNAME);
        }
        return userService.register(registerDto);
    }
}
